package com.yxinsur.imc.web.controller.business;

import com.yxinsur.imc.business.form.ContractExpenseForm;
import com.yxinsur.imc.business.service.IImcContractExpenseExpressionService;
import com.yxinsur.imc.business.service.IImcContractExpenseService;
import com.yxinsur.imc.business.vo.ImcContractExpenseVo;
import com.yxinsur.imc.common.annotation.Log;
import com.yxinsur.imc.common.core.controller.BaseController;
import com.yxinsur.imc.common.core.domain.AjaxResult;
import com.yxinsur.imc.common.core.page.TableDataInfo;
import com.yxinsur.imc.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 协议费用科目
 *
 * @author imc
 * @date 2021-07-28
 */
@Api(value = "6.1.协议-费用科目模块接口服务", tags = {"6.1.协议-费用科目模块接口服务"})
@RestController
@RequestMapping("/business/expense")
public class ImcContractExpenseController extends BaseController {

    @Autowired
    private IImcContractExpenseService imcContractExpenseService;
    @Autowired
    private IImcContractExpenseExpressionService imcContractExpenseExpressionService;

    /**
     * 协议费用科目-查询列表
     *
     * @param id 协议id
     * @return TableDataInfo
     */
    @ApiOperation("协议费用科目-查询列表")
    @Log(title = "协议费用科目-查询列表")
    @GetMapping("/list/{id}")
    public TableDataInfo listExpense(@PathVariable("id") Long id) {
        startPage();
        List<ImcContractExpenseVo> list = this.imcContractExpenseService.listImcContractExpenseByContractId(id);
        return getDataTable(list);
    }

    /**
     * 协议费用科目-查询列表
     *
     * @param id 协议id
     * @return TableDataInfo
     */
    @ApiOperation("协议费用科目-查询列表")
    @Log(title = "协议费用科目-查询列表")
    @GetMapping("/listNoPage/{id}")
    public TableDataInfo listNoPageExpense(@PathVariable("id") Long id) {
        List<ImcContractExpenseVo> list = this.imcContractExpenseService.listImcContractExpenseByContractId(id);
        return getDataTable(list);
    }

    /**
     * 协议费用科目-删除
     */
    @ApiOperation("协议费用科目-删除")
    @Log(title = "协议费用科目-删除", businessType = BusinessType.UPDATE)
    @GetMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        return this.imcContractExpenseService.deleteImcContractExpenseById(id);
    }

    /**
     * 生成&检测口径
     */
    @ApiOperation("协议费用科目-生成&检测口径")
    @Log(title = "协议费用科目-生成&检测口径", businessType = BusinessType.INSERT)
    @PostMapping("/expression/check")
    public AjaxResult checkExpenseExpression(@RequestBody ContractExpenseForm contractExpenseForm) {
        return this.imcContractExpenseExpressionService.checkExpenseExpression(contractExpenseForm);
    }

    /**
     * 查询协议费用科目口径列表
     *
     * @param id 协议费用科目id
     * @return TableDataInfo
     */
    @ApiOperation("查询协议费用科目口径列表")
    @Log(title = "查询协议费用科目口径列表")
    @GetMapping("/expression/list/{id}")
    public AjaxResult listExpenseExpression(@PathVariable("id") Long id) {
        return AjaxResult.success(this.imcContractExpenseExpressionService.listExpenseExpressionByContractExpenseId(id));
    }

    /**
     * 新增协议费用科目
     *
     * @param contractExpenseForm ContractExpenseForm
     * @return AjaxResult
     */
    @ApiOperation("新增协议费用科目")
    @Log(title = "新增协议费用科目", businessType = BusinessType.INSERT)
    @PostMapping("/expression/add")
    public AjaxResult addExpenseExpression(@RequestBody ContractExpenseForm contractExpenseForm) {
        return imcContractExpenseExpressionService.insertImcContractExpenseExpression(contractExpenseForm);
    }

    /**
     * 修改协议费用科目
     */
    @ApiOperation("修改协议费用科目")
    @Log(title = "修改协议费用科目", businessType = BusinessType.UPDATE)
    @PostMapping("/expression/edit")
    public AjaxResult editExpenseExpression(@RequestBody ContractExpenseForm contractExpenseForm) {
        return imcContractExpenseExpressionService.updateImcContractExpenseExpression(contractExpenseForm);
    }

    /**
     * 查询口径变量
     */
    @ApiOperation("查询口径变量")
    @Log(title = "查询口径变量")
    @GetMapping("/list/variable")
    public AjaxResult listVariable() {
        return AjaxResult.success(this.imcContractExpenseExpressionService.listVariable());
    }

    /**
     * 查询处理策略
     */
    @ApiOperation("查询处理策略")
    @Log(title = "查询处理策略")
    @GetMapping("/list/strategy")
    public AjaxResult listStrategy() {
        return AjaxResult.success(this.imcContractExpenseExpressionService.listStrategy());
    }
}
